import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { setupSwagger } from '@app/common/plugins/setupSwagger';
import { TransformInterceptor } from '@app/common/interceptors/transform.interceptor';
import { HttpExceptionFilter } from '@app/common/filters/http-exception.filter';
import { NestExpressApplication } from '@nestjs/platform-express';
import { EnvEnum } from '@app/common/enum/envEnum';
import configs from '@app/common/configs';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    cors: true,
  });
  // 配置插件
  setupSwagger(app, {
    title: '全栈之巅后台API',
    description: '用于后台页面操作数据',
    version: '1.0',
    path: 'docs',
  });
  // 统一返回数据格式
  app.useGlobalInterceptors(new TransformInterceptor());
  // 全局拦截错误
  app.useGlobalFilters(new HttpExceptionFilter());
  // 托管静态资源
  if (process.env.IS_OSS === 'false') {
    app.useStaticAssets('uploads', {
      prefix: '/uploads',
    });
  }

  // 挂载静态资源(后台系统)
  // app.useStaticAssets('/admin', {
  //   prefix: '/admin',
  // });

  const PORT = 3009;
  await app.listen(PORT);
  console.log(`nest server running at http://localhost:3009/docs`);
}

bootstrap();
